package com.imay.live.adapter;

import android.text.TextUtils;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;
import com.imay.live.model.CelebrityModel;
import com.imay.live.model.CelebrityTitleModel;
import com.imay.live.model.UserModel;
import com.imay.live.view.CelebrityLinearLayout;
import com.imay.live.R;

import java.util.List;

/**
 * Created by liangzhenxiong on 2017/4/6 0006.
 * 发现-分类
 */

public class CelebrityLinearAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity, BaseViewHolder> {


    public final static int VIEWTYPE_LINEAR_TITLE = 2;//名人标题
    public final static int VIEWTYPE_LINEAR_HEADER = 3;//名人多列头像


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public CelebrityLinearAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(VIEWTYPE_LINEAR_TITLE, R.layout.item_celebrity_titlemore);
        addItemType(VIEWTYPE_LINEAR_HEADER, R.layout.item_celebrity);

    }


    @Override
    protected void convert(final BaseViewHolder helper, MultiItemEntity item) {
        if (item.getItemType() == VIEWTYPE_LINEAR_TITLE) {
            if (item instanceof CelebrityTitleModel) {
                if (helper.getLayoutPosition() == 0) {

                }
                final CelebrityTitleModel c = (CelebrityTitleModel) item;
                TextView tv_title = helper.getView(R.id.tv_cele_title);
                tv_title.setText(c.getTitle());
                helper.addOnClickListener(R.id.rl_cele);
            }

        } else if (item.getItemType() == VIEWTYPE_LINEAR_HEADER) {
            if (item instanceof CelebrityModel) {
                CelebrityModel celebrityModel = (CelebrityModel) item;
                CelebrityLinearLayout celebrityLinearLayout = helper.getView(R.id.ll_celebrity);
                if (celebrityLinearLayout == null) {
                    return;
                }
                String img0 = null, img1 = null, img2 = null;
                String name0 = null, name1 = null, name2 = null;
                long uid0 = 0, uid1 = 0, uid2 = 0;

                for (UserModel hotusermodel : celebrityModel.getUserModels()) {
                    if (TextUtils.isEmpty(img0)) {
                        img0 = hotusermodel.getImgHead();
                        name0 = hotusermodel.getNick();
                        uid0 = hotusermodel.getUid();
                        continue;
                    }
                    if (TextUtils.isEmpty(img1)) {
                        img1 = hotusermodel.getImgHead();
                        name1 = hotusermodel.getNick();
                        uid1 = hotusermodel.getUid();
                        continue;
                    }
                    if (TextUtils.isEmpty(img2)) {
                        img2 = hotusermodel.getImgHead();
                        name2 = hotusermodel.getNick();
                        uid2 = hotusermodel.getUid();
                    } else {
                        break;
                    }
                }
//                celebrityLinearLayout.setImg("https://imgs.imay.com/pic-28081-1492339842-4233.png", "https://imgs.imay.com/pic-28081-1492339842-4233.png", "https://imgs.imay.com/pic-28081-1492339842-4233.png");
                celebrityLinearLayout.setImg(img0, img1, img2);
                celebrityLinearLayout.setText(name0, name1, name2);
                celebrityLinearLayout.setUids(uid0, uid1, uid2);
            }
        }
    }
}
